﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace Project_Proto
{
  public class XMlSerializer<T> where T : class,new ( )
  {
    public T Deserialize ( Stream inputStream )
    {
      try
      {
        XmlSerializer serializer = new XmlSerializer ( typeof ( T ) );
        T result = ( T )serializer.Deserialize ( inputStream );
        return result;
      }
      catch (Exception ex )
      {
        Console.WriteLine ("desierialisieren fehlgeschlagen  " +ex.Message);
      }
      return null;
    }

    public void Serialize ( Stream outputStream, T target )
    {
      try
      {
        XmlSerializer serializer = new XmlSerializer ( typeof ( T ) );
        serializer.Serialize ( outputStream, target );
        outputStream.Close ( );
      }
      catch (Exception)
      {
      }
    }
  }
}
